package com.ztgf.file.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.file.models.vo.FileInfoVO;
import com.ztgf.pay.models.service.IPayUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.file.mapper.FileInfoMapper;
import com.ztgf.file.models.service.IFileInfoService;
import com.ztgf.file.models.dto.FileInfoDTO;

import java.util.List;

/**
 * 文件信息表控制器
 *
 * @author mxli
 * @Date 2020-07-10 14:19:43
 */
@DubboService
public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfoDTO> implements IFileInfoService{

    @DubboReference
    private IPayUserService payUserService;

    @Override
    public Page<FileInfoVO> queryChildUserPageList(Long fileUserId, Integer type, Integer pageNo, Integer pageSize) {
        if(pageNo == null || pageNo <=0){
            pageNo = 1;
        }

        if(pageSize == null || pageSize <= 0){
            pageSize = 20;
        }
        Page<FileInfoVO> page = new Page<>(pageNo, pageSize);
        List<FileInfoVO> list = this.baseMapper.queryChildUserPageList(page, fileUserId, type);
        if(list != null && list.size() > 0){
            page.setRecords(list);
        }
        return page;
    }

    @Override
    public List<FileInfoVO> queryChildUserList(Long fileUserId, Integer type, List<Long> childUserIds) {
        return  this.baseMapper.queryChildUserList(fileUserId, type, childUserIds);
    }

    @Override
    public List<FileInfoVO> queryListByUrl(Long fileUserId, String[] urls) {
        return  this.baseMapper.queryListByUrl(fileUserId, urls);
    }

    @Override
    public Result queryTest(Long userId, int accountType) {
        return this.payUserService.getUserBalance(userId, accountType);
    }
}
